<template>
  <div class="postBar" @click="postBarClick">
    <!-- 三图 -->
    <div v-if="postItem.images.length >= 3" class="postThree">
      <h3 class="post_title">{{postItem.title}}</h3>
      <!--三图 文本 -->
      <p class="post_text" v-html="postItem.summary"></p>
      <!--三图 图片 -->
      <div class="three_img">
        <img v-for="(item,index) of threeImg" :key="index" :src="item" alt />
      </div>
      <!-- 信息 -->
      <div class="post_info">
        <div class="info_left">
          <span class="info_cityName">
            <i class="el-icon-location-outline"></i>
            {{postItem.cityName}}
          </span>
          by
          <span class="info_account">
            <!-- {{$axios.defaults.baseURL }} -->
            <img
              class="account_img"
              :src="$axios.defaults.baseURL + postItem.account.defaultAvatar"
              alt
            />
            <span class="account_nickname">{{postItem.account.nickname}}</span>
          </span>
          <span class="info_watch">
            <i class="el-icon-view"></i>
            {{postItem.watch}}
          </span>
        </div>
        <div class="info_right">
          <span>{{postItem.like}}</span>赞
        </div>
      </div>
    </div>
    <!-- 单图 -->
    <div v-if="postItem.images.length < 3" class="postOne">
      <div class="one_left">
        <img :src="postItem.images[0]" alt />
      </div>
      <div class="one_right">
        <h3 class="post_title">{{postItem.title}}</h3>
        <p class="post_text" v-html="postItem.summary"></p>
        <!-- 信息 -->
        <div class="post_info">
          <div class="info_left">
            <span class="info_cityName">
              <i class="el-icon-location-outline"></i>
              {{postItem.cityName}}
            </span>
            by
            <span class="info_account">
              <!-- {{$axios.defaults.baseURL }} -->
              <img
                class="account_img"
                :src="$axios.defaults.baseURL + postItem.account.defaultAvatar"
                alt
              />
              <span class="account_nickname">{{postItem.account.nickname}}</span>
            </span>
            <span class="info_watch">
              <i class="el-icon-view"></i>
              {{postItem.watch}}
            </span>
          </div>
          <div class="info_right">
            <span>{{postItem.like}}</span>赞
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  props: ["postItem"],
  methods: {
    postBarClick(){
      this.$emit('postBarClick',this.postItem.id)
    }
  },
  computed: {
    // 三图图片控制
    threeImg() {
      // console.log('this.postItem.images: ', this.postItem.images.length);
      if (this.postItem.images.length > 3) {
        this.postItem.images.length = 3;
      }
      const { images } = this.postItem;
      return images;
    }
  }
};
</script>

<style lang="less" scoped>
.postBar {
  cursor: pointer;
  // padding: 25px 0;
  margin-bottom: 25px;
  border-bottom: 1px solid #eeeeee;
}
// info 信息
.post_info {
  line-height: 50px;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  .info_left {
    font-size: 12px;
    color: #999999;
    // 地址
    .info_cityName {
      padding: 0 8px;
    }
    .info_account {
      padding-right: 10px;
      .account_img {
        width: 15px;
        height: 15px;
      }
    }
    //  名字
    .account_nickname {
      color: orange;
    }
  }
  .info_right {
    color: orange;
    span {
      padding: 0 5px;
    }
  }
}
// 标题
.post_title {
  font-weight: 400;
  line-height: 60px;
  height: 60px;
  overflow: hidden;
  &:hover {
    color: orange;
  }
}
// 文字主体
.post_text {
  height: 55px;
  // 多行CSS 隐藏
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 3; // 行数
  -webkit-box-orient: vertical;
}
// 三图
.postThree {
  // 三张图片
  .three_img {
    margin: 16px 0 8px 0;
    width: 100%;
    display: flex;
    justify-content: space-between;
    img {
      width: 220px;
      height: 150px;
    }
  }
}
// 单图
.postOne {
  display: flex;
  justify-content: space-between;
  // align-items: center;
  .one_left {
    img {
      width: 220px;
      height: 150px;
    }
  }
  .one_right {
    // padding-left: 15px;
    width: 465px;
  }
}
</style>